// The "fastbird engine" library is distributed under the MIT license:
// 
// Copyright (c) 2013 fastbird(jungwan82@naver.com)
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.

#pragma once
#ifndef IEngine_header_included
#define IEngine_header_included

#include <Engine/Config.h>
#include <Engine/SmartPtr.h>
#include <Engine/IInputListener.h>

#define FB_DEFAULT_DEBUG_ARG "%s(%d): %s() - %s", __FILE__, __LINE__, __FUNCTION__
#define FB_LOG(msg) fastbird::IEngine::Log(FB_DEFAULT_DEBUG_ARG, (msg));
#define FB_LOG_LAST_ERROR() fastbird::IEngine::LogLastError(__FILE__, __LINE__, __FUNCTION__)
namespace fastbird
{
	struct GlobalEnv;
	class IRenderer;
	class ICamera;
	class IScene;
	class IFont;
	class Vec2I;
	class Vec3;

	class CLASS_DECLSPEC IEngine : public ReferenceCounter
	{
	public:
		static IEngine* CreateInstance();
		static void Log(const char* szFmt, ...);
		static void LogLastError(const char* file, int line, const char* function);

		virtual ~IEngine(){}
		virtual void GetGlobalEnv(GlobalEnv** outGloblEnv) = 0;
		virtual HWND CreateEngineWindow(int x, int y, int width, int height, 
			const char* title, WNDPROC winProc) = 0;
		virtual HWND GetWindowHandle() const = 0;
		enum RENDERER_TYPE { D3D9, D3D11, OPENGL };
		virtual bool InitEngine(RENDERER_TYPE rendererType) = 0;
		virtual inline IRenderer* GetRenderer() const = 0;
		virtual inline IScene* GetScene() const = 0;
		virtual inline IFont* GetFont() const = 0;

		virtual void UpdateFrame(float dt) = 0;

		virtual ICamera* CreateAndRegisterCamera(const char* cameraName) = 0;
		virtual void RegisterCamera(const char* cameraName, ICamera* pCamera) = 0;
		
		// Terrain
		// numVertX * numVertY = (2^n+1) * (2^m+1)
		virtual bool CreateTerrain(int numVertX, int numVertY, float distance, const char* heightmapFile = 0) = 0;

		virtual void AddInputListener(IInputListener* pInputListener, 
			IInputListener::INPUT_LISTEN_CATEGORY category, int priority) = 0;

#ifdef _FBENGINE_FOR_WINDOWS_
		virtual bool WinProc( HWND window, UINT msg, WPARAM wp, LPARAM lp ) = 0;
#elif _FBENGINE_FOR_LINUX_

#endif

		virtual void QueueText(const Vec2I& pos, WCHAR* text, const Vec3& color, float size) = 0;
	};

	typedef SmartPtr<IEngine> EnginePtr;
};

#endif